Skip to content

Fix possible NPE in InteractiveShellRunner#1320

Merged
fmbenhassine merged 1 commit intospring-projects:mainfrom
czpilar:patches/npe-interactive-shell
Mar 25, 2026
Merged

Fix possible NPE in InteractiveShellRunner#1320
fmbenhassine merged 1 commit intospring-projects:mainfrom
czpilar:patches/npe-interactive-shell

Conversation

@czpilar
Copy link
Copy Markdown
Contributor

@czpilar czpilar commented Feb 15, 2026

This is a small fix of potentional NPE in Interactive Shell Runner.

Consider following configuration:

package org.springframework.shell.samples.helloworld.boot;

import org.jline.reader.LineReader;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.shell.core.command.annotation.Command;
import org.springframework.shell.core.command.annotation.Option;
import org.springframework.shell.jline.JLineInputProvider;
import org.springframework.util.StringUtils;

@SpringBootApplication
public class SpringShellApplication {

	public static void main(String[] args) {
		new SpringApplicationBuilder(SpringShellApplication.class).properties("spring.shell.debug.enabled=true")
			.run(args);
	}

	@Command(name = "hello")
	public void sayHello(@Option String name) {
		System.out.println("Hello " + name + "!");
	}

	@Bean
	@Primary
	public JLineInputProvider myInputProvider(LineReader lineReader) {
		return new JLineInputProvider(lineReader) {
			@Override
			public String readInput() {
				String s = super.readInput();
				return StringUtils.hasLength(s) ? s : null;
			}
		};
	}

}

Just simple enter which produces null in readInput method will end in NPE.

obrazek

Signed-off-by: David Pilar <david@czpilar.net>
@czpilar
Copy link
Copy Markdown
Contributor Author

czpilar commented Feb 15, 2026

It is similiar issue as in #1258 where it was fixed for Non Interactive Shell Runner.

@fmbenhassine fmbenhassine merged commit 9f35a7d into spring-projects:main Mar 25, 2026
2 checks passed
@fmbenhassine fmbenhassine added the type/bug Is a bug report label Mar 25, 2026
@fmbenhassine fmbenhassine added this to the 4.0.2 milestone Mar 25, 2026
@czpilar czpilar deleted the patches/npe-interactive-shell branch April 1, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug Is a bug report

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants